{}
//1 unkown类型
let a: unknown = 'hello word!';
let b: string = a as string;
console.log(a);

let c: string = '99';
let d: number = c as unknown as number;
console.log(d);

//2 void和never的区别
let fn1 = function (): void {
  return undefined || null;
};

let fn2 = (): never => {
  throw new Error('出错啦');
};


//3 函数的声明

// 3.1 推断
let fn3 = function (name: string, age: number): number[] {
  return [1, 2, 3];
};

// 3.2 类型声明
let fn32: Function = (name: number, age?: number): any[] => {
  return [1, 'wdq', false];
}

// 3.3 结构定义 结合接口
enum Sex {
  boy,
  girl,
}
interface fn4Type{
  name: string,
  age: number,
  sex?: number,
  [name: string]: any
}
type Fn4 = (user: fn4Type) => void;
let fn4: Fn4 = (user: fn4Type): void  => {
  console.log(user.name + user.age + (user.sex ? user.sex : 0) );
};
fn4({
  name: 'liming',
  age: 14,
  // sex: 2,
  color: 'agreen',
})



//4 剩余参数的使用
function fn5(arr: any[], ...args: any[]): Array<number> {
  arr.push(args);
  return arr
}

console.log(fn5(['arr:'], 1, 'hello', true));

//5 元组的使用
let arr: (string | null | number)[] = [null, 99, 'csdcd'];
// arr[0].length; 
console.log(arr);

let arr2: [boolean, string, number] = [false, 'anme', 99];
console.log(arr2[1].length);


// 6 断言
// 不同写法
let aa: '小黄' = '小黄';
const bb = '小红';
let ee = '小懒222' as const;
// let ee = <const>'小懒222';
let ff = [aa, 1, true, 'hello'];
let ff2 = [aa, 1, true, 'hello'] as const;
let ff3 = <const>[aa, 1, true, 'hello'];
const gg = {
  name: aa,
} as const;

let cc: string = '小懒';
cc = 'csca';


// 结构中使用断言
function hd() {
  let a: string = 'www.baidu.com';
  let b = (name: string, age: number) => name + age;
  return [a, b];
};
// (1)
// let [m, n] = hd();
// console.log((n as (name: string, age: number) => string)('zhangsan', 13))

// (2)
let [m, n] = hd();
// console.log((n as Function)('lisi', 99))

// (3)
function hd2() {
  let a: string = 'www.baidu.com';
  let b = (name: string, age: number) => name + age;
  return [a, b];
};
let [mm, nn] = hd2()  as [string, Function]
// console.log(nn('lisi', 99))

// (4)
function hd3() {
  let a: string = 'www.baidu.com';
  let b = (name: string, age: number) => name + age;
  return [a, b] as [typeof a, typeof b];
};
let [m1, n1] = hd3();
// console.log(n1('lisi', 99))

// (5)
function hd4() {
  let a: string = 'www.baidu.com';
  let b = (name: string, age: number) => name + age;
  return [a, b] as const;
};
let [m2, n2] = hd4();
console.log(n2('lisi00', 99))


// 非空断言
let div: HTMLDivElement = document.querySelector('#hd')!;
let div2: HTMLDivElement = document.querySelector('#hd') as HTMLDivElement;
let body: HTMLBodyElement = document.querySelector('body') as HTMLBodyElement;